import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/**
 * @author tongchen
 * @create 2023-01-06 15:44
 */
public class Greedy {
    public static void main(String[] args) {
        //创建所有地区
        HashSet<String> allAreas = new HashSet<>();
        allAreas.add("北京");
        allAreas.add("上海");
        allAreas.add("天津");
        allAreas.add("广州");
        allAreas.add("深圳");
        allAreas.add("成都");
        allAreas.add("杭州");
        allAreas.add("大连");
        //创建地区广播
        HashMap<String, HashSet<String>> broadcasts = new HashMap<>();
        //创建单个广播
        HashSet<String> hashSet1 = new HashSet<>();
        hashSet1.add("北京");
        hashSet1.add("上海");
        hashSet1.add("天津");
        HashSet<String> hashSet2 = new HashSet<>();
        hashSet2.add("北京");
        hashSet2.add("广州");
        hashSet2.add("深圳");
        HashSet<String> hashSet3 = new HashSet<>();
        hashSet3.add("成都");
        hashSet3.add("上海");
        hashSet3.add("杭州");
        HashSet<String> hashSet4 = new HashSet<>();
        hashSet4.add("天津");
        hashSet4.add("上海");
        HashSet<String> hashSet5 = new HashSet<>();
        hashSet5.add("杭州");
        hashSet5.add("大连");
        //广播台的加入
        broadcasts.put("K1",hashSet1);
        broadcasts.put("K2",hashSet2);
        broadcasts.put("K3",hashSet3);
        broadcasts.put("K4",hashSet4);
        broadcasts.put("K5",hashSet5);
        //创建结果容器
        ArrayList<String> result = new ArrayList<>();
        //创建temp实现比较结果的创建
        HashSet<String> temp = new HashSet<>();
        String maxSize="";
        int size1=0;
        while(!allAreas.isEmpty()){
            maxSize="";//重置maxsize
            //重置temp
            size1=0;
            for (String board: broadcasts.keySet()) {
                temp.clear();
                HashSet<String> strings = broadcasts.get(board);
                temp.addAll(strings);
                //寻找交集
                temp.retainAll(allAreas);
                //判断是否加入
                if(temp.size()>0&&(maxSize.equals("")||temp.size()>size1)){
                    //maxsize更替
                    size1=temp.size();
                    maxSize=board;
                }
            }
            if(!maxSize.equals("")){
                result.add(maxSize);
                allAreas.removeAll(broadcasts.get(maxSize));
            }
        }

        System.out.println(result);
    }
}
